import router from '@system.router';
import request from '@ohos.request';
import fetch from '@system.fetch';
import qs from 'querystring';
import prompt from '@system.prompt';
export default {
    data: {
        name:"",
        agreestatue:false,
        account:"",
        password:"",
        confirm_pasword:""
    },
    onShow(){
        router.clear();
    },
    doname(e){
        this.name = e.value;
    },
    doaccount(e){
        this.account = e.value;
    },
    dopassword(e){
        this.password = e.value;
    },
    dopasswordagain(e){
        this.confirm_pasword = e.value;
    },
    denglu(){
        router.push({
            uri:"pages/register/register"
        })
    },
    agree(e){
        this.agreestatue=e.checked;
    },
    zhuce(){
        if(this.agreestatue==true){
            router.push({
                uri:"pages/shouye/shouye"
            })
            fetch.fetch({
                url: "http://124.70.5.225:8000/api/register/",
                data: qs.stringify({
                    'name': this.name,
                    'account': this.account,
                    'password': this.password,
                    'confirm_password': this.confirm_pasword
                }),
                responseType: "json",
                method: "POST",
                success: (resp) => {
                    this.winfo = resp.data;
                    //打印获取数据
                    console.info("获取成功")
                    console.info("返回的数据：" + this.winfo)
                    //如果验证通过则进行页面跳转
                    if (this.winfo == "注册成功") {
                        //router方法进行页面的跳转
                        router.push({
                            uri: "pages/regiser/regiser",
                            params:{
                                username:this.name
                            }
                        })
                        prompt.showToast({
                            message: '注册成功',
                            duration: 2000,
                        });
                    }
                },
                fail: (resp) => {
                    //打印失败原因
                    this.winfo = resp.data;
                    console.info("获取失败")
                    console.info("失败原因：" + this.winfo)
                    prompt.showToast({
                        message: '注册失败',
                        duration: 2000,
                    });
                }
            })
        }else{
            prompt.showToast({
                message:"请先同意平台协议",
                duration:2000
            })
        }
    }
}
